#include "gl_extensions.h"


#if !defined(GL_GLEXT_PROTOTYPES)
PFNGLGENBUFFERSARBPROC glGenBuffers;
PFNGLDELETEBUFFERSARBPROC glDeleteBuffers;
PFNGLBINDBUFFERARBPROC glBindBuffer;
PFNGLBUFFERDATAARBPROC glBufferData;
PFNGLBUFFERSUBDATAARBPROC glBufferSubData;
PFNGLMAPBUFFERARBPROC glMapBuffer;
PFNGLUNMAPBUFFERARBPROC glUnmapBuffer;
PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements;

PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTexture;
PFNGLMULTITEXCOORD1FARBPROC glMultiTexCoord1f;
PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2f;
PFNGLMULTITEXCOORD3FARBPROC glMultiTexCoord3f;
PFNGLMULTITEXCOORD4FARBPROC glMultiTexCoord4f;
PFNGLACTIVETEXTUREARBPROC glActiveTexture;
#endif //GL_GLEXT_PROTOTYPES

void sdl_load_gl_extensions()
{
    static bool loaded = false;

    if (loaded) return;

#if !defined(GL_GLEXT_PROTOTYPES)
    if (gl_extension_supported("GL_ARB_vertex_buffer_object")) {
        glDrawRangeElements = sdl_gl_getproc<PFNGLDRAWRANGEELEMENTSPROC > ("glDrawRangeElements");

        glGenBuffers = sdl_gl_getproc<PFNGLGENBUFFERSARBPROC > ("glGenBuffersARB");
        glDeleteBuffers = sdl_gl_getproc<PFNGLDELETEBUFFERSARBPROC > ("glDeleteBuffersARB");
        glBindBuffer = sdl_gl_getproc<PFNGLBINDBUFFERARBPROC > ("glBindBufferARB");
        glBufferData = sdl_gl_getproc<PFNGLBUFFERDATAARBPROC > ("glBufferDataARB");
        glBufferSubData = sdl_gl_getproc<PFNGLBUFFERSUBDATAARBPROC > ("glBufferSubDataARB");
        glMapBuffer = sdl_gl_getproc<PFNGLMAPBUFFERARBPROC > ("glMapBufferARB");
        glUnmapBuffer = sdl_gl_getproc<PFNGLUNMAPBUFFERARBPROC > ("glUnmapBufferARB");
    } else {
        _err("opengl", "GL_ARB_vertex_buffer_object not present. Sorry, no fun today.");
    }

    if (gl_extension_supported("GL_ARB_multitexture")) {
        glClientActiveTexture = sdl_gl_getproc<PFNGLCLIENTACTIVETEXTUREARBPROC > ("glClientActiveTextureARB");
        glMultiTexCoord1f = sdl_gl_getproc<PFNGLMULTITEXCOORD1FARBPROC > ("glMultiTexCoord1fARB");
        glMultiTexCoord2f = sdl_gl_getproc<PFNGLMULTITEXCOORD2FARBPROC > ("glMultiTexCoord2fARB");
        glMultiTexCoord3f = sdl_gl_getproc<PFNGLMULTITEXCOORD3FARBPROC > ("glMultiTexCoord3fARB");
        glMultiTexCoord4f = sdl_gl_getproc<PFNGLMULTITEXCOORD4FARBPROC > ("glMultiTexCoord4fARB");
        glActiveTexture = sdl_gl_getproc<PFNGLACTIVETEXTUREARBPROC > ("glActiveTextureARB");
    } else {
        _err("opengl", "GL_ARB_multitexture not present. What kind of hardware are you on?");
    }
#endif //GL_GLEXT_PROTOTYPES

    loaded = true;
}

